const app = getApp();
async function GetOpenData() {
  return await wx.cloud.callFunction({
    name: 'openapi',
    data: {
      action: 'getOpenData'
    }
  })
}
async function EduAuthUser(xh, pwd) {
  return await wx.cloud.callFunction({
    name: 'eduapi',
    data: {
      action: 'authUser',
      xh: xh,
      pwd: pwd
    },
    
  })
}
async function getCjcx(xh) {
  let res = await wx.cloud.callFunction({
    name: 'eduapi',
    data: {
      action: 'getCjcx',
      xh: xh
    },
    fail:r=>{
      wx.redirectTo({
        url: '/pages/login/login',
      })
    }
  })
  var nres = []
  var glist = res.result;
  //console.log(res)
  /*
  正向映射
  */
  try {
    glist.forEach(function (ele, index) {
      nres.push({
        sujectname: ele.kcmc,
        subjectscore: ele.zcj,
        subjectgrade: ele.xf,
        subjectype: ele.kclbmc,
        subjectgroup: ele.kcxzmc
      })
    })
    return nres;
  } catch (error) {
    return [];
  }
}
async function getKbcxAzc(xh,zc){
  let res = await  wx.cloud.callFunction({
    name: 'eduapi',
    data: {
      action: 'getKbcxAzc',
      xh: xh,
      zc:zc
    },
    fail:r=>{
      wx.redirectTo({
        url: '/pages/login/login',
      })
    }
  })
  return res;
}
module.exports = {
  GetOpenData,
  EduAuthUser,
  getCjcx,
  getKbcxAzc
}